package com.example.gmwang.washapplication.utils;


import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;


/**
 * Created by Admin on 2017/8/2.
 */

public class AesEncrypt extends BaseActivity {
    public static String uuid = "";
    public static String version;
    public static String token = "";

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);


    }

    //加密
    public static String GetAes() {
        version = (String) SpUtils.getString(getmContext(), "version", "");
        if (version == null) {
            version = "";
        }
        uuid = (String) SpUtils.getString(getmContext(), "uuid", "");
        if (uuid == null) {
            uuid = "";
        }
        token = (String) SpUtils.getString(getmContext(), "token", "");
        if (token == null) {
            token = "";
        }
        long time = System.currentTimeMillis();
        String md5 = SignValue.getMD5(time, version, uuid, token);
        StringBuffer buffer = new StringBuffer();
        buffer.append("appid=").append(1).append("&");
        buffer.append("token=").append(token).append("&");
        buffer.append("apptype=").append(1).append("&");
        buffer.append("pf=").append("").append("&");
        buffer.append("v=").append("").append("&");
        buffer.append("vv=").append("V" + version).append("&");
        buffer.append("uuid=").append(uuid).append("&");
        buffer.append("time=").append(time).append("&");
        buffer.append("imei=").append("").append("&");
        buffer.append("imsi=").append("").append("&");
        buffer.append("mac=").append("").append("&");
        buffer.append("ua=").append("").append("&");
        buffer.append("m1=").append(md5);
        Log.e("uuid", uuid);
        String encrypt = null;
        try {
            encrypt = AESUtil.encrypt(CommonState.AesKey, buffer.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return encrypt;
    }

    //加密
    public static String GetAesMore(StringBuffer sb) {
        version = (String) SpUtils.getString(getmContext(), "version", "");
        if (version == null) {
            version = "";
        }
        long time = System.currentTimeMillis();
        uuid = (String) SpUtils.getString(getmContext(), "uuid", "");
        if (uuid == null) {
            uuid = "";
        }
        token = (String) SpUtils.getString(getmContext(), "token", "");
        if (token == null) {
            token = "";
        }
        String md5 = SignValue.getMD5(time, version, uuid, token);
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("appid=").append(1).append("&");
        stringBuffer.append("token=").append(token).append("&");
        stringBuffer.append("apptype=").append(1).append("&");
        stringBuffer.append("pf=").append("").append("&");
        stringBuffer.append("v=").append("").append("&");
        stringBuffer.append("vv=").append("V" + version).append("&");
        stringBuffer.append("uuid=").append(uuid).append("&");
        stringBuffer.append("time=").append(time).append("&");
        stringBuffer.append("imei=").append("").append("&");
        stringBuffer.append("imsi=").append("").append("&");
        stringBuffer.append("mac=").append("").append("&");
        stringBuffer.append("ua=").append("").append("&");
        stringBuffer.append("m1=").append(md5).append("&").append(sb);
        Log.e("buffer", stringBuffer.toString());
        String encrypt = null;
        try {
            encrypt = AESUtil.encrypt(CommonState.AesKey, stringBuffer.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return encrypt;
    }
}
